package edu.hit.wxdemo.resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public ResponseEntity<String> hello(@RequestParam String name) {
        String ans = toColorHello(name);
        System.out.println(ans);
        return ResponseEntity.ok(ans);
    }

    @GetMapping("/demo")
    public ResponseEntity<String> hello() {
        String ans = toColorHello(this.getClass().toString());
        System.out.println(ans);
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ans);
    }

    /**
     * 控制台带颜色
     * @param name 姓名
     * @return 带ANSI颜色的问好
     */
    private String toColorHello(@RequestParam String name) {
        return "[38;5;86;1;6m 你好, " + name + "![0m";
    }
}
